import {Injectable} from '@angular/core';
import {BaseService, httpOptions} from '../../../../core/service/base.service';
import {_HttpClient} from '@delon/theme';
import {Observable} from 'rxjs';
import {catchError, tap} from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class DeviceInspectionTemplateItemService extends BaseService {

  getUrl(): string {
    return 'api/device-inspection-template-item';
  }

  constructor(http: _HttpClient) {
    super(http);
  }

  saveList(object: any): Observable<any> {
    return this.http.post<any>(this.getUrl() + '/save-list', object, httpOptions).pipe(
      tap((obj: any) => this.log(`added object =${obj}`)),
      catchError(this.handleError<any>('addany')),
    );
  }

  getByDeviceInspectionTemplateId(deviceInspectionTemplateId: string): Observable<any> {
    const url = `${this.getUrl() + '/get-by-device-inspection-template-id'}/${deviceInspectionTemplateId}`;
    return this.http.get<any>(url).pipe(
      tap(_ => this.log(`fetched object get-by-device-inspection-template-id=${deviceInspectionTemplateId}`)),
      catchError(this.handleError<any>(`getany get-by-device-inspection-template-id=${deviceInspectionTemplateId}`)),
    );
  }
}
